<a href="<?php echo url('/user/view', array('id' => $model->user_id)) ?>" title="Name: <?php echo $model->username; ?> - Age: <?php echo $model->age ?>"><img src="<?php echo $model->getAvatarUrl() ?>">
    <div class="offline online-<?php echo $model->user_id ?>" is-check=''>Online</div>
</a>
<script>
    $(document).ready(function() {
<?php
/*
 * check online after 5s 
 */
?>

	$('.online-<?php echo $model->user_id ?>').each(function() {
	    var isCheck = $(this).attr('is-check');

	    if (!isCheck) {

		$('.online-<?php echo $model->user_id ?>').attr('is-check', 1);
		var checkOnline = setInterval(function() {

		    $.post('<?php echo SITE_NAME_URL ?>chat/checkonline', {idUser: <?php echo $model->user_id ?>}, function(response) {
			$('.online-<?php echo $model->user_id ?>').attr('is_checked', 1);
			if (response == 'true') {
			    $('.online-<?php echo $model->user_id ?>').removeClass('offline');
			    $('.online-<?php echo $model->user_id ?>').addClass('online');
			    $('.online-<?php echo $model->user_id ?>').html('Online');
			} else {
			    $('.online-<?php echo $model->user_id ?>').removeClass('online');
			    $('.online-<?php echo $model->user_id ?>').addClass('offline');
			    $('.online-<?php echo $model->user_id ?>').html('Offline');
			}
		    });


		}, 5000);
	    }

	});


    });
</script>